#include "bimossensor.h"

BimosSensor::BimosSensor(int ordinal) :
    name("Sensor " + QString::number(ordinal)),
    ordinal(ordinal), volt(0)
{

}


int BimosSensor::getOrdinal(){
    return ordinal;
}

double BimosSensor::getVolt(){
    return volt;
}


double BimosSensor::getMeanVolt(){
    return mean/mean_cnt;
}

void BimosSensor::calculateMean(){
    mean += getVolt();

    if (mean_cnt++ > mean_size){
        mean = mean/mean_size;
        mean_cnt = 1;
    }
}

void BimosSensor::setVolt(double newVolt){
    volt = newVolt;
    calculateMean();
    emit valueChanged(this);
}

QDataStream& operator<<(QDataStream &outStream, const BimosSensor &data)
{

    outStream << (quint8)data.ordinal;

    return outStream;
}

QDataStream& operator>>(QDataStream &inStream, BimosSensor &data)
{

    inStream >> data.ordinal;

    return inStream;
}
